import com.sun.jmx.remote.internal.ArrayQueue;

import java.util.Objects;
import java.util.Stack;

/**
 * @description:
 * @Author: wuzhenbin
 * @CreateTime: 2025/2/16
 */
public class leetcode_20 {
    public static void main(String[] args) {

    }
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<Character>();
        if(Objects.equals(s, ""))return true;
        boolean res = false;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)=='('||s.charAt(i)=='{'||s.charAt(i)=='['){
                stack.push(s.charAt(i));
            } else if (s.charAt(i)==')') {
                if(stack.isEmpty())return false;
                if(!stack.isEmpty()&&stack.pop()!='(')return false;
            }
            else if (s.charAt(i)=='}') {
                if(stack.isEmpty())return false;
                if(!stack.isEmpty()&&stack.pop()!='{')return false;
            }
            else if (s.charAt(i)==']') {
                if(stack.isEmpty())return false;
                if(!stack.isEmpty()&&stack.pop()!='[')return false;
            }
        }
        return stack.isEmpty();
    }
}
